<template>
  <div class="list-item" @click="toDetail">
    <div class="i-top">
      <span class="color-black">{{ itemData.customerName }} {{ filterPhone(itemData.customerPhone) }}</span>
      <span class="color-normal">{{ getDictName('CTM_INTENTION_LEVEL', itemData.intendedLevel) }}</span>
    </div>
    <div class="content">
      <div>
        意向加盟城市：<span class="color-black">{{ itemData.intendedCity }}</span>
      </div>
      <div>
        招商经理：<span class="color-black">{{ itemData.managerName }}</span>
      </div>
      <div>
        特许经营市场：<span class="color-black">{{ itemData.marketName }}</span>
      </div>
      <div>
        市场类型：<span class="color-black">{{ getDictName('TOBE_MARKET_TYPE', itemData.marketType) }}</span>
      </div>
      <div>
        加盟状态：<span class="color-black">{{ getDictName('CTM_JOIN_IN_STATE', itemData.joinStatus) }}</span>
      </div>
      <div>
        意向客户分配时间:<span class="color-black">{{ itemData.allotTime }}</span>
      </div>
    </div>
    <div class="i-bottom">
      <span class="desc" @click.stop="onMarketChange">市场变更记录</span>
      <div class="btns" v-if="itemData.joinStatus === 'A'">
        <div class="btn radius-larg ctm-btn-grey-outline" @click.stop="onStop">终止</div>
        <div class="btn radius-larg ctm-btn-grey-outline" @click.stop="onHandover">交接</div>
        <div class="btn radius-larg ctm-btn-grey-outline" @click.stop="onEdit">编辑</div>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
  import { defineComponent } from 'vue'
  import { filterPhone } from '@/utils'
  export default defineComponent({
    name: 'FollowUpItem',
    props: {
      itemData: {
        type: Object,
        default: () => {}
      },
      dictData: {
        type: Object,
        default: () => {}
      }
    },
    setup(props, { emit }) {
      const toDetail = () => {
        emit('detail')
      }
      const onMarketChange = () => {
        emit('marketChange')
      }

      const onStop = () => {
        emit('stop')
      }

      const onHandover = () => {
        emit('handover')
      }
      const onEdit = () => {
        emit('edit')
      }
      const onDetail = () => {
        emit('detail')
      }

      const getDictName = (dictType: string, code: any) => {
        if (!dictType || [undefined, null, ''].includes(code)) return ''
        let name = code
        const dictList = props.dictData[dictType] || []
        if (dictList.length > 0) {
          const obj = dictList.find((v: any) => v.dictCode === `${code}`)
          name = obj?.dictName || code
        }
        return name
      }

      return {
        toDetail,
        onMarketChange,
        onEdit,
        onStop,
        onHandover,
        onDetail,
        getDictName,
        filterPhone
      }
    }
  })
</script>
<style lang="less" scoped>
  .list-item {
    margin-bottom: 8px;
    padding: 16px;
    background: var(--bg-global-weaker);
    border-radius: 8px;
    font: var(--font-main-body);
    color: var(--texticon-default-stronger);

    .i-top {
      display: flex;
      justify-content: space-between;
      align-items: center;
      height: 20px;
      font: var(--font-main-title-strengthen);
    }

    .content {
      margin-top: 8px;
      margin-bottom: 16px;
      div {
        padding: 2px 0;
        display: flex;
        justify-content: space-between;

        font: var(--font-main-body);
        color: var(--texticon-default-stronger);
        line-height: 20px;
      }
    }

    .i-bottom {
      display: flex;
      justify-content: space-between;
      align-items: center;
      height: 40px;

      .desc {
        color: var(--texticon-color-warning-normal);
        font-size: 14px;
        font-weight: 400;
        text-decoration: underline;
      }

      .btns {
        display: flex;
        justify-content: flex-end;
        .btn {
          width: 88px;
          height: 36px;
          margin-left: 8px;
          display: flex;
          align-items: center;
          justify-content: center;
        }
      }
    }
  }
</style>
